package com.s4j.struts.biz.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.Action;
import com.s4j.core.common.BaseAction;
import com.s4j.core.common.MyDateUtils;
import com.s4j.core.common.StringUtils;
import com.s4j.core.conset.Constant;
import com.s4j.core.datagrid.DatagridPaging;
import com.s4j.core.manager.model.SysModule;
import com.s4j.core.manager.model.SysUser;
import com.s4j.struts.biz.model.BizLiAppr;
import com.s4j.struts.biz.model.BizLiBgwm;
import com.s4j.struts.biz.model.BizLiCheck;
import com.s4j.struts.biz.model.BizLiCombin;
import com.s4j.struts.biz.model.BizLiCompute;
import com.s4j.struts.biz.model.BizLiGyvm;
import com.s4j.struts.biz.model.BizLiMmgyz;
import com.s4j.struts.biz.model.BizLiOtherreson;
import com.s4j.struts.biz.model.BizLiReson;
import com.s4j.struts.biz.model.BizLiTreat;
import com.s4j.struts.biz.model.BizLiTreathis;
import com.s4j.struts.biz.model.BizLiYgwm;
import com.s4j.struts.biz.model.BizLiZswm;
import com.s4j.struts.biz.model.PatientDoc;
import com.s4j.struts.biz.service.LiverService;

@Controller("com.s4j.struts.biz.action.LiverDocAction")
@Scope("prototype")
public class LiverDocAction extends BaseAction {
	
	@Resource
	private LiverService liverService;
	
	private PatientDoc patientDoc;
	
	private BizLiAppr liAppr;
	private BizLiCheck liCheck;
	private BizLiCompute liCompute;
	private BizLiCombin liCombin;
	private BizLiMmgyz liMmgyz;
	private BizLiOtherreson liOther;
	private BizLiReson liReson;
	private BizLiTreat liTreat;
	private BizLiTreathis treathis;

	public String mainQuery() {
		
		DatagridPaging datagridPaging = liverService.findUserByPaging(getPage(), getRows(), patientDoc);
		
		this.setDatagridPaging(datagridPaging);
		
		return Action.SUCCESS;
	}

	@Override
	public void init(SysModule module, HttpServletRequest request) {
//		Long docId = new Long(request.getParameter("patientDoc.docId"));
//		request.setAttribute("patientDoc", liverService.getPatientDoc(docId));
		if("docmgr_liverdocmgr_docEdit".equals(module.getModuleNo())) {
			String docId = request.getParameter("docId");
			request.setAttribute("docId", docId);
		}
		
		if("docmgr_liverdocmgr_common".equals(module.getModuleNo())) {
			String docId = request.getParameter("docId");
			if(docId != null && !"".equals(docId)) {
				request.setAttribute("patientDoc", liverService.getPatientDoc(new Long(docId)));
			}
		}
		
		if("docmgr_liverdocmgr_appr".equals(module.getModuleNo())) {
			Long docId = new Long(request.getParameter("docId"));
			request.setAttribute("patientDoc", liverService.getPatientDoc(docId));
			request.setAttribute("liAppr", liverService.getLiApprByPatientId(docId));
			request.setAttribute("liReson", liverService.getLiResonByPatientId(docId));
			request.setAttribute("liCompute", liverService.getLiComputeByPatientId(docId));
			request.setAttribute("liCombin", liverService.getLiCombinByPatientId(docId));
			request.setAttribute("liOther", liverService.getLiOtherresonByPatientId(docId));
		}
		
		if("docmgr_liverdocmgr_labcheck".equals(module.getModuleNo())) {
			Long docId = new Long(request.getParameter("docId"));
			request.setAttribute("patientDoc", liverService.getPatientDoc(docId));
			request.setAttribute("liCheck", liverService.getLiCheckByPatientId(docId));
		}
		
		if("docmgr_liverdocmgr_other".equals(module.getModuleNo())) {
			Long docId = new Long(request.getParameter("docId"));
			request.setAttribute("patientDoc", liverService.getPatientDoc(docId));
		}
		
		if("docmgr_liverdocmgr_treathis".equals(module.getModuleNo())) {
			Long docId = new Long(request.getParameter("docId"));
			request.setAttribute("patientDoc", liverService.getPatientDoc(docId));
			BizLiTreathis treathis = liverService.getLiTreathisByPatientId(docId);
			request.setAttribute("treathis", treathis);
			setYgMedicineFlag(treathis, request);
			setBgMedicineFlag(treathis, request);
			setZsMedicineFlag(treathis, request);
			setGyMedicineFlag(treathis, request);
		} 
	}
	
	public String liverDoc_commonSave() {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		SysUser login = (SysUser)session.getAttribute(Constant.BG_LOGIN_USER);
		if(patientDoc.getDocId() == null) {
			patientDoc.setDiseaseType(Constant.PATIENTDOC_DISEASETYPE_LIVER);
			patientDoc.setInputDate(MyDateUtils.getCurDateTime());
			patientDoc.setInputUserName(login.getUserName());
			liverService.saveCommon(patientDoc);
		} else {
			patientDoc.setDiseaseType(Constant.PATIENTDOC_DISEASETYPE_LIVER);
			liverService.updateCommon(patientDoc);
		}
		
		this.getResultMap().put("docId", patientDoc.getDocId());
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_apprSave1() throws Exception {
		if(liAppr.getApprId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			liAppr.setPatient(patient);
			if(!StringUtils.isNullOrBlank(liAppr.getQuezhen_day())) {
				int age = MyDateUtils.differenceDate("yyyy-MM-dd", patient.getBirthday(), liAppr.getQuezhen_day());
				liAppr.setQuezhen_age(age/12);
			}
			liverService.save(liAppr);
		} else {
			BizLiAppr persis = liverService.get(BizLiAppr.class, liAppr.getApprId());
			persis.setHbflag(liAppr.getHbflag());
			persis.setQibing_day(liAppr.getQibing_day());
			persis.setQuezhen_day(liAppr.getQuezhen_day());
			persis.setQuezhen_hospital(liAppr.getQuezhen_hospital());
			persis.setZhenduan_standard(liAppr.getZhenduan_standard());
			if(!StringUtils.isNullOrBlank(liAppr.getQuezhen_day())) {
				int age = MyDateUtils.differenceMonth("yyyy-MM-dd", persis.getPatient().getBirthday(), liAppr.getQuezhen_day());
				persis.setQuezhen_age(age/12);
			} else {
				persis.setQuezhen_age(null);
			}
			liverService.update(persis);
		}
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_apprSave2() {
		if(liReson.getResonId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			liReson.setPatient(patient);
			liverService.save(liReson);
		} else {
			BizLiReson persis = liverService.get(BizLiReson.class, liReson.getResonId());
			persis.setYixing(liReson.getYixing());
			persis.setBinxing(liReson.getBinxing());
			persis.setJiujingxing(liReson.getJiujingxing());
			persis.setFeijiujing(liReson.getFeijiujing());
			persis.setYaowu(liReson.getYaowu());
			persis.setZishen(liReson.getZishen());
			persis.setYuanfadg(liReson.getYuanfadg());
			persis.setYuanfadz(liReson.getYuanfadz());
			persis.setOther(liReson.getOther());
			liverService.update(persis);
		}
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_apprSave3() {		
		if(liCompute.getComputeId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			liCompute.setPatient(patient);
			liverService.save(liCompute);
		} else {
			BizLiCompute persis = liverService.get(BizLiCompute.class, liCompute.getComputeId());
			persis.setDcq(liCompute.getDcq());
			persis.setGxnb(liCompute.getGxnb());
			persis.setFushui(liCompute.getFushui());
			persis.setDhs(liCompute.getDhs());
			persis.setBdb(liCompute.getBdb());
			persis.setPt(liCompute.getPt());
			persis.setMeld(liCompute.getMeld());
			persis.setMjm_bc(liCompute.getMjm_bc());
			persis.setMjm_ct(liCompute.getMjm_ct());
			persis.setSdw_bw(liCompute.getSdw_bw());
			persis.setSdw_color(liCompute.getSdw_color());
			persis.setSdw_red(liCompute.getSdw_red());
			persis.setTjpz(liCompute.getTjpz());
			persis.setPhd_bc(liCompute.getPhd_bc());
			persis.setPhd_ct(liCompute.getPhd_ct());
			persis.setPcz_bc(liCompute.getPcz_bc());
			persis.setPcz_ct(liCompute.getPcz_ct());
			persis.setPkd_bc(liCompute.getPkd_bc());
			persis.setPkd_ct(liCompute.getPkd_ct());
			persis.setBxb(liCompute.getBxb());
			persis.setXxb(liCompute.getXxb());
			persis.setHxb(liCompute.getHxb());
			persis.setXhdb(liCompute.getXhdb());
			persis.setHxbbj(liCompute.getHxbbj());
			persis.setBfz(liCompute.getBfz());
			liverService.update(persis);
		}		
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_apprSave4() {		
		if(liCombin.getCombinId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			liCombin.setPatient(patient);
			liverService.save(liCombin);
		} else {
			BizLiCombin persis = liverService.get(BizLiCombin.class, liCombin.getCombinId());
			persis.setTnb(liCombin.getTnb());
			persis.setTnb_ywzl(liCombin.getTnb_ywzl());
			persis.setGxy(liCombin.getGxy());
			persis.setGxy_ywzl(liCombin.getGxy_ywzl());
			persis.setOther(liCombin.getOther());
			liverService.update(persis);
		}
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_apprSave5() {		
		if(liOther.getOtherresonId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			liOther.setPatient(patient);
			liverService.save(liOther);
		} else {
			BizLiOtherreson persis = liverService.get(BizLiOtherreson.class, liOther.getOtherresonId());
			persis.setXy_year(liOther.getXy_year());
			persis.setXy_num(liOther.getXy_num());
			persis.setYj_year(liOther.getYj_year());
			persis.setYj_num(liOther.getXy_num());
			persis.setJzs(liOther.getJzs());
			liverService.update(persis);
		}
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_apprSave6() {		
		if(liMmgyz.getMmgyzId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			liMmgyz.setPatient(patient);
			liverService.save(liMmgyz);
		} else {
			BizLiMmgyz persis = liverService.get(BizLiMmgyz.class, liMmgyz.getMmgyzId());
			persis.setOperatetime(liMmgyz.getOperatetime());
			persis.setFzy(liMmgyz.getFzy());
			persis.setLx(liMmgyz.getLx());
			persis.setFyjl(liMmgyz.getFyjl());
			persis.setYyqzsj(liMmgyz.getYyqzsj());
			persis.setZdjl(liMmgyz.getZdjl());
			persis.setTyyy(liMmgyz.getTyyy());
			liverService.update(persis);
		}
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_apprSave7() {		
		if(liTreat.getTreatId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			liTreat.setPatient(patient);
			liverService.save(liTreat);
		} else {
			BizLiTreat persis = liverService.get(BizLiTreat.class, liTreat.getTreatId());			
			persis.setLx(liMmgyz.getLx());
			persis.setFyjl(liMmgyz.getFyjl());
			persis.setYyqzsj(liMmgyz.getYyqzsj());
			persis.setZdjl(liMmgyz.getZdjl());
			persis.setTyyy(liMmgyz.getTyyy());
			
			
			liverService.update(persis);
		}
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_checkSave1() {		
		if(liCheck.getCheckId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			liCheck.setPatient(patient);
			liverService.save(liCheck);
		} else {
			BizLiCheck persis = liverService.get(BizLiCheck.class, liCheck.getCheckId());
			persis.setXfxhb(liCheck.getXfxhb());
			persis.setXfxplt(liCheck.getXfxplt());
			persis.setNxgninr(liCheck.getNxgninr());
			persis.setNxgnpt(liCheck.getNxgnpt());
			persis.setGgnalb(liCheck.getGgnalb());
			persis.setGgnalt(liCheck.getGgnalt());
			persis.setGgtbil(liCheck.getGgtbil());
			persis.setQtafp(liCheck.getQtafp());
			persis.setQtca(liCheck.getQtca());
			persis.setQtcr(liCheck.getQtcr());
			persis.setYxx(liCheck.getYxx());
			persis.setBingli(liCheck.getBingli());
			persis.setMzsz(liCheck.getMzsz());
			persis.setYzyy(liCheck.getYzyy());
			liverService.update(persis);
		}
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_treathisSave1() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String[] ygwmId = request.getParameterValues("ygwmId");
		String[] ygwm_drugname = request.getParameterValues("ygwm_drugname");
		String[] ygwm_fyjl = request.getParameterValues("ygwm_fyjl");
		String[] ygwm_yyqzsj = request.getParameterValues("ygwm_yyqzsj");
		String[] ygwm_tyyy = request.getParameterValues("ygwm_tyyy");
		String[] ygwm_xqxzh = request.getParameterValues("ygwm_xqxzh");
		String[] ygwm_dnaqs = request.getParameterValues("ygwm_dnaqs");
		String[] ygwm_dnatw = request.getParameterValues("ygwm_dnatw");
		String[] ygwm_dnatf = request.getParameterValues("ygwm_dnatf");
		String[] ygwm_dnazy = request.getParameterValues("ygwm_dnazy");
		String[] ygwm_dnany = request.getParameterValues("ygwm_dnany");
		
		String[] bgwmId = request.getParameterValues("bgwmId");
		String[] bgwm_drugname = request.getParameterValues("bgwm_drugname");
		String[] bgwm_fyjl = request.getParameterValues("bgwm_fyjl");
		String[] bgwm_yyqzsj = request.getParameterValues("bgwm_yyqzsj");
		String[] bgwm_tyyy = request.getParameterValues("bgwm_tyyy");
		String[] bgwm_dnaqs = request.getParameterValues("bgwm_dnaqs");
		String[] bgwm_dnatw = request.getParameterValues("bgwm_dnatw");
		String[] bgwm_dnatf = request.getParameterValues("bgwm_dnatf");
		String[] bgwm_dnafe = request.getParameterValues("bgwm_dnafe");
		String[] bgwm_dnazy = request.getParameterValues("bgwm_dnazy");
		String[] bgwm_dnany = request.getParameterValues("bgwm_dnany");
		
		String[] zswmId = request.getParameterValues("zswmId");
		String[] zswm_drugname = request.getParameterValues("zswm_drugname");
		String[] zswm_fyjl = request.getParameterValues("zswm_fyjl");
		String[] zswm_yyqzsj = request.getParameterValues("zswm_yyqzsj");
		String[] zswm_zdjl = request.getParameterValues("zswm_zdjl");
		String[] zswm_tyyy = request.getParameterValues("zswm_tyyy");
		String[] zswm_lx = request.getParameterValues("zswm_lx");
		
		if(treathis.getTreatId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			treathis.setPatient(patient);
			liverService.save(treathis);
		}
		for(int i=0; i<ygwm_drugname.length; i++) {
			if(StringUtils.isBlank(ygwm_drugname[i])) {
				continue;
			}
			if(StringUtils.isBlank(ygwmId[i])) {
				BizLiYgwm wm = new BizLiYgwm();
				wm.setDrugname(ygwm_drugname[i].trim());
				wm.setFyjl(ygwm_fyjl[i]);
				wm.setYyqzsj(ygwm_yyqzsj[i]);
				wm.setTyyy(ygwm_tyyy[i]);
				wm.setXqxzh(ygwm_xqxzh[i]);
				wm.setDnaqs(ygwm_dnaqs[i]);
				wm.setDnatw(ygwm_dnatw[i]);
				wm.setDnatf(ygwm_dnatf[i]);
				wm.setDnazy(ygwm_dnazy[i]);
				wm.setDnany(ygwm_dnany[i]);
				wm.setTreathis(treathis);
				liverService.save(wm);
			} else {
				BizLiYgwm wm = liverService.get(BizLiYgwm.class, new Long(ygwmId[i]));
				wm.setDrugname(ygwm_drugname[i].trim());
				wm.setFyjl(ygwm_fyjl[i]);
				wm.setYyqzsj(ygwm_yyqzsj[i]);
				wm.setTyyy(ygwm_tyyy[i]);
				wm.setXqxzh(ygwm_xqxzh[i]);
				wm.setDnaqs(ygwm_dnaqs[i]);
				wm.setDnatw(ygwm_dnatw[i]);
				wm.setDnatf(ygwm_dnatf[i]);
				wm.setDnazy(ygwm_dnazy[i]);
				wm.setDnany(ygwm_dnany[i]);
				wm.setTreathis(treathis);
				liverService.update(wm);
			}
		}
		
		for(int i=0; i<bgwm_drugname.length; i++) {
			if(StringUtils.isBlank(bgwm_drugname[i])) {
				continue;
			}
			if(StringUtils.isBlank(bgwmId[i])) {
				BizLiBgwm wm = new BizLiBgwm();
				wm.setDrugname(bgwm_drugname[i].trim());
				wm.setFyjl(bgwm_fyjl[i]);
				wm.setYyqzsj(bgwm_yyqzsj[i]);
				wm.setTyyy(bgwm_tyyy[i]);
				wm.setDnaqs(bgwm_dnaqs[i]);
				wm.setDnatw(bgwm_dnatw[i]);
				wm.setDnatf(bgwm_dnatf[i]);
				wm.setDnafe(bgwm_dnafe[i]);
				wm.setDnazy(bgwm_dnazy[i]);
				wm.setDnany(bgwm_dnany[i]);
				wm.setTreathis(treathis);
				liverService.save(wm);
			} else {
				BizLiBgwm wm = liverService.get(BizLiBgwm.class, new Long(bgwmId[i]));
				wm.setDrugname(bgwm_drugname[i].trim());
				wm.setFyjl(bgwm_fyjl[i]);
				wm.setYyqzsj(bgwm_yyqzsj[i]);
				wm.setTyyy(bgwm_tyyy[i]);
				wm.setDnaqs(bgwm_dnaqs[i]);
				wm.setDnatw(bgwm_dnatw[i]);
				wm.setDnatf(bgwm_dnatf[i]);
				wm.setDnafe(bgwm_dnafe[i]);
				wm.setDnazy(bgwm_dnazy[i]);
				wm.setDnany(bgwm_dnany[i]);
				wm.setTreathis(treathis);
				liverService.update(wm);
			}
		}
		
		for(int i=0; i<zswm_drugname.length; i++) {
			if(StringUtils.isBlank(zswm_drugname[i])) {
				continue;
			}
			if(StringUtils.isBlank(zswmId[i])) {
				BizLiZswm wm = new BizLiZswm();
				wm.setDrugname(zswm_drugname[i].trim());
				wm.setFyjl(zswm_fyjl[i]);
				wm.setYyqzsj(zswm_yyqzsj[i]);
				wm.setZdjl(zswm_zdjl[i]);
				wm.setTyyy(zswm_tyyy[i]);
				wm.setLx(zswm_lx[i]);
				wm.setTreathis(treathis);
				liverService.save(wm);
			} else {
				BizLiZswm wm = liverService.get(BizLiZswm.class, new Long(zswmId[i]));
				wm.setDrugname(zswm_drugname[i].trim());
				wm.setFyjl(zswm_fyjl[i]);
				wm.setYyqzsj(zswm_yyqzsj[i]);
				wm.setZdjl(zswm_zdjl[i]);
				wm.setTyyy(zswm_tyyy[i]);
				wm.setLx(zswm_lx[i]);
				wm.setTreathis(treathis);
				liverService.update(wm);
			}
		}
		
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	public String liverDoc_treathisSave2() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String[] gywmId = request.getParameterValues("gywmId");
		String[] gywm_operation = request.getParameterValues("gywm_operation");
		String[] gywm_operatetime = request.getParameterValues("gywm_operatetime");
		String[] gywm_fzy = request.getParameterValues("gywm_fzy");
		String[] gywm_lx = request.getParameterValues("gywm_lx");
		String[] gywm_drugname = request.getParameterValues("gywm_drugname");
		String[] gywm_fyjl = request.getParameterValues("gywm_fyjl");
		String[] gywm_yyqzsj = request.getParameterValues("gywm_yyqzsj");
		String[] gywm_zdjl = request.getParameterValues("gywm_zdjl");
		String[] gywm_tyyy = request.getParameterValues("gywm_tyyy");
				
		if(treathis.getTreatId() == null) {
			PatientDoc patient = liverService.getPatientDoc(patientDoc.getDocId());
			treathis.setPatient(patient);
			liverService.save(treathis);
		}
		for(int i=0; i<gywm_drugname.length; i++) {
			if(StringUtils.isBlank(gywm_drugname[i])) {
				continue;
			}
			if(StringUtils.isBlank(gywmId[i])) {
				BizLiGyvm wm = new BizLiGyvm();
				wm.setDrugname(gywm_drugname[i].trim());
				wm.setFyjl(gywm_fyjl[i]);
				wm.setZdjl(gywm_zdjl[i]);
				wm.setYyqzsj(gywm_yyqzsj[i]);
				wm.setTyyy(gywm_tyyy[i]);
				wm.setTreathis(treathis);
				liverService.save(wm);
			} else {
				BizLiGyvm wm = liverService.get(BizLiGyvm.class, new Long(gywmId[i]));
				wm.setDrugname(gywm_drugname[i].trim());
				wm.setFyjl(gywm_fyjl[i]);
				wm.setZdjl(gywm_zdjl[i]);
				wm.setYyqzsj(gywm_yyqzsj[i]);
				wm.setTyyy(gywm_tyyy[i]);
				wm.setTreathis(treathis);
				liverService.update(wm);
			}
		}
		for(int i=0; i<gywm_operation.length; i++) {
			if(StringUtils.isBlank(gywm_operation[i])) {
				continue;
			}
			if(StringUtils.isBlank(gywmId[i])) {
				BizLiGyvm wm = new BizLiGyvm();
				wm.setOperation(gywm_operation[i].trim());
				wm.setOperatetime(gywm_operatetime[i]);
				wm.setFzy(gywm_fzy[i]);
				wm.setLx(gywm_lx[i]);
				wm.setTreathis(treathis);
				liverService.save(wm);
			} else {
				BizLiGyvm wm = liverService.get(BizLiGyvm.class, new Long(gywmId[i]));
				wm.setOperation(gywm_operation[i].trim());
				wm.setOperatetime(gywm_operatetime[i]);
				wm.setFzy(gywm_fzy[i]);
				wm.setLx(gywm_lx[i]);
				wm.setTreathis(treathis);
				liverService.update(wm);
			}
		}
				
		
		this.getResultMap().put("rtnCode", Action.SUCCESS);
		this.getResultMap().put("rtnMsg", "保存成功");
		
		return Action.SUCCESS;
	}
	
	private void setYgMedicineFlag(BizLiTreathis treathis2,
			HttpServletRequest request) {
		if(treathis2 == null) {
			return;
		}
		List<BizLiYgwm> ygwmList = treathis2.getYgwm();
		for(int i=0; i<ygwmList.size(); i++) {
			BizLiYgwm wm = ygwmList.get(i);
			if("拉米夫定".equals(wm.getDrugname())) {
				request.setAttribute("ygwm_1", 1);
			} else if("恩替卡韦".equals(wm.getDrugname())) {
				request.setAttribute("ygwm_2", 1);
			} else if("阿德福韦酯".equals(wm.getDrugname())) {
				request.setAttribute("ygwm_3", 1);
			} else if("替比夫定".equals(wm.getDrugname())) {
				request.setAttribute("ygwm_4", 1);
			} else if("替诺福韦".equals(wm.getDrugname())) {
				request.setAttribute("ygwm_5", 1);
			} 
		}
	}
	
	private void setBgMedicineFlag(BizLiTreathis treathis2,
			HttpServletRequest request) {
		if(treathis2 == null) {
			return;
		}
		List<BizLiBgwm> bgwmList = treathis2.getBgwm();
		for(int i=0; i<bgwmList.size(); i++) {
			BizLiBgwm wm = bgwmList.get(i);
			if("短效干扰素".equals(wm.getDrugname())) {
				request.setAttribute("bgwm_1", 1);
			} else if("长效干扰素".equals(wm.getDrugname())) {
				request.setAttribute("bgwm_2", 1);
			} else if("利巴韦林".equals(wm.getDrugname())) {
				request.setAttribute("bgwm_3", 1);
			} else if("Sofosbuvir (SOF)".equals(wm.getDrugname())) {
				request.setAttribute("bgwm_4", 1);
			} else if("simeprevir(SIM)".equals(wm.getDrugname())) {
				request.setAttribute("bgwm_5", 1);
			} else if("daclatasvir(DCV)".equals(wm.getDrugname())) {
				request.setAttribute("bgwm_6", 1);
			} 
		}
	}
	
	private void setZsMedicineFlag(BizLiTreathis treathis2,
			HttpServletRequest request) {
		if(treathis2 == null) {
			return;
		}
		List<BizLiZswm> zswmList = treathis2.getZswm();
		for(int i=0; i<zswmList.size(); i++) {
			BizLiZswm wm = zswmList.get(i);
			if("醋酸泼尼松".equals(wm.getDrugname())) {
				request.setAttribute("zswm_1", 1);
			} else if("甲泼尼龙".equals(wm.getDrugname())) {
				request.setAttribute("zswm_2", 1);
			} else if("硫唑嘌呤".equals(wm.getDrugname())) {
				request.setAttribute("zswm_3", 1);
			} else if("环孢素".equals(wm.getDrugname())) {
				request.setAttribute("zswm_4", 1);
			} else if("他克莫司".equals(wm.getDrugname())) {
				request.setAttribute("zswm_5", 1);
			} else if("吗替麦考酚酯".equals(wm.getDrugname())) {
				request.setAttribute("zswm_6", 1);
			} else if("熊去氧胆酸".equals(wm.getDrugname())) {
				request.setAttribute("zswm_7", 1);
			} 
		}
	}
	
	private void setGyMedicineFlag(BizLiTreathis treathis2,
			HttpServletRequest request) {
		if(treathis2 == null) {
			return;
		}
		List<BizLiGyvm> gywmList = treathis2.getGywm();
		for(int i=0; i<gywmList.size(); i++) {
			BizLiGyvm wm = gywmList.get(i);
			if("门体分流术".equals(wm.getOperatetime())) {
				request.setAttribute("gywm_1", 1);
			} else if("脾切除术".equals(wm.getOperatetime())) {
				request.setAttribute("gywm_2", 1);
			} else if("脾栓塞术".equals(wm.getOperatetime())) {
				request.setAttribute("gywm_3", 1);
			} else if("食管静脉套扎".equals(wm.getOperatetime())) {
				request.setAttribute("gywm_4", 1);
			} else if("食管胃底静脉硬化剂".equals(wm.getOperatetime())) {
				request.setAttribute("gywm_5", 1);
			} else if("普萘洛尔".equals(wm.getOperatetime())) {
				request.setAttribute("gywm_6", 1);
			} else if("硝酸甘油类药物".equals(wm.getOperatetime())) {
				request.setAttribute("gywm_7", 1);
			} 
		}
	}

	public PatientDoc getPatientDoc() {
		return patientDoc;
	}

	public void setPatientDoc(PatientDoc patientDoc) {
		this.patientDoc = patientDoc;
	}

	public BizLiAppr getLiAppr() {
		return liAppr;
	}

	public void setLiAppr(BizLiAppr liAppr) {
		this.liAppr = liAppr;
	}

	public BizLiCheck getLiCheck() {
		return liCheck;
	}

	public void setLiCheck(BizLiCheck liCheck) {
		this.liCheck = liCheck;
	}

	public BizLiCompute getLiCompute() {
		return liCompute;
	}

	public void setLiCompute(BizLiCompute liCompute) {
		this.liCompute = liCompute;
	}

	public BizLiCombin getLiCombin() {
		return liCombin;
	}

	public void setLiCombin(BizLiCombin liCombin) {
		this.liCombin = liCombin;
	}

	public BizLiMmgyz getLiMmgyz() {
		return liMmgyz;
	}

	public void setLiMmgyz(BizLiMmgyz liMmgyz) {
		this.liMmgyz = liMmgyz;
	}

	public BizLiOtherreson getLiOther() {
		return liOther;
	}

	public void setLiOther(BizLiOtherreson liOther) {
		this.liOther = liOther;
	}

	public BizLiReson getLiReson() {
		return liReson;
	}

	public void setLiReson(BizLiReson liReson) {
		this.liReson = liReson;
	}

	public BizLiTreat getLiTreat() {
		return liTreat;
	}

	public void setLiTreat(BizLiTreat liTreat) {
		this.liTreat = liTreat;
	}

	public BizLiTreathis getTreathis() {
		return treathis;
	}

	public void setTreathis(BizLiTreathis treathis) {
		this.treathis = treathis;
	}
	
	
}
